import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import ViewHolder;
public class Adapter extends BaseAdapter {
    private ArrayList<HashMap<Integer,Object>> _ = new ArrayList<>();

    private Context _mContext;
    private int _mlayoutId = 0;
    //布局ID
    public Adapter(Context context){
        this._mContext = context;
    }
     @Override
    public int getCount() {
        return _mHashMaps.size();
      //返回ArrayList的长度，作为总项/条目数量
    }
    
    @Override
    public HashMap<Integer, Object> getItem(int position) {
        return _mHashMaps.get(position);
      //返回HaspMap实例
    }
    
    @Override
    public long getItemId(int position) {
        return position;
      //这里的position便是项/条目id
    }

    public void add(HashMap<Integer,Object> hashMap){
        this._mHashMaps.add(hashMap);
    }
 //对某个条目进行修改
    public void set(int point,HashMap<Integer,Object> hashMap){
        this._mHashMaps.set(point,hashMap);
    }
    
    public void set(int point,int Rid,Object state){
        this._mHashMaps.get(point).put(Rid,state)
    }

    public void setItemLayout(int id){
        this._mlayoutId = id;
    }
     
    public void clear(){
        this._mHashMaps.clear();
    }

    
    private void viewcont(ViewHolder viewHolder, HashMap item) {
        Iterator iter = item.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            int a = (int)entry.getKey();
            Object b =entry.getValue();
            viewHolder.setView(a,b);
        }
     private ViewHolder getViewHolder(int position, View convertView,ViewGroup parent)
    {
        return ViewHolder.get(_mContext, convertView, parent, _mlayoutId,position);
    }

    @Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(_mlayoutId == 0){
        return null;
    }
    final ViewHolder viewHolder = getViewHolder(position, convertView, parent);
    viewcont(viewHolder, getItem(position));
    return viewHolder.getConvertView();
  }

}